package com.example.myandroidapp1;

import android.content.Context;
import android.content.res.AssetManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Align;
import android.graphics.Rect;
import android.graphics.Typeface;
import android.view.View;

public class MyGFXView extends View {

	private Bitmap greenBall;
	private float changingY;
	private Typeface font;

	public MyGFXView(Context context) {
		super(context);
		greenBall = BitmapFactory.decodeResource(getResources(),
				R.drawable.green_ball);
		changingY = 0;
		font = Typeface.createFromAsset(context.getAssets(), "G-Unit.TTF");
	}

	@Override
	protected void onDraw(Canvas canvas) {
		// TODO Auto-generated method stub
		super.onDraw(canvas);
		canvas.drawColor(Color.WHITE);

		Paint textPaint = new Paint();
		textPaint.setARGB(500, 255, 10, 50);
		textPaint.setTextAlign(Align.CENTER);
		textPaint.setTextSize(200);
		textPaint.setTypeface(font);
		canvas.drawText("Nikunj Jariwala", canvas.getWidth() / 2, 200,
				textPaint);

		canvas.drawBitmap(greenBall, canvas.getWidth() / 2, changingY, null);
		if (changingY < canvas.getHeight()) {
			changingY += 10;
		} else {
			changingY = 0;
		}

		Rect middleRect = new Rect();
		middleRect.set(0, 400, canvas.getWidth(), 550);
		Paint ourBlue = new Paint();
		ourBlue.setColor(Color.BLUE);
		canvas.drawRect(middleRect, ourBlue);

		invalidate();
	}

}
